Bulk Messaging System

Documentation

Whats app client configuration

Introduction#

This page explains how the application configures and manages the WhatsApp client, focusing on:

  • Puppeteer launch arguments and browser behavior
  • Authentication via QR code and session persistence
  • Session storage and cleanup
  • Rate limiting and throttling
  • Proxy configuration options
  • Performance tuning and resource management
  • Error handling, timeouts, and recovery strategies

Project structure#

The WhatsApp integration lives in the Electron application’s main process and is exposed to the renderer via a secure IPC bridge. The renderer component renders the UI and orchestrates user actions.

Core components#

  • Electron main process initializes the WhatsApp client with puppeteer options and emits status events.
  • Preload exposes a controlled API surface to the renderer.
  • Renderer component manages UI state, QR display, and user actions.

Key responsibilities:

  • Launch configuration and browser flags
  • QR code generation and display
  • Session lifecycle (start, authenticate, disconnect, logout)
  • Cleanup of cached sessions and auth artifacts

Architecture overview#

End-to-end flow for connecting and sending messages:

Detailed component analysis#

Puppeteer launch arguments and browser behavior#

The WhatsApp client uses a headless Chromium instance configured via puppeteer. The main process sets:

  • Headless mode: enabled
  • Hardened Chromium flags for stability and sandbox compatibility

Important implications:

  • Headless mode reduces resource overhead and avoids GUI rendering.
  • Sandboxing flags improve compatibility on restricted environments but may limit GPU acceleration.

Recommended adjustments (conceptual):

  • To enable visible debugging, toggle headless to false and add viewport/user agent overrides.
  • For performance, consider disabling unneeded chrome features via additional puppeteer args.

Authentication strategy: QR code, session persistence, reconnection#

  • Authentication strategy: LocalAuth persists session data locally.
  • QR code generation: The client emits a QR string; the main process converts it to a data URL and sends it to the renderer.
  • Status events: The app listens for ready, authenticated, and auth_failure events.
  • Disconnection handling: The client emits a disconnected event; the main process clears state and sets the client to null.

Reconnection mechanism:

  • The UI checks current status and prevents starting a second client while one is running.
  • On successful authentication, the QR is cleared and the UI shows a success state.

LocalAuth stores session artifacts in a local directory managed by whatsapp-web.js. The application cleans these directories on startup and logout:

  • Cache directory cleanup on startup and logout
  • Auth directory cleanup on logout

Guidance:

  • If you need to force a fresh session, rely on the cleanup routines.
  • For multi-device scenarios, manage separate profiles by controlling the LocalAuth baseDir.

Rate limiting, message throttling, and API usage#

The application implements a simple throttle between sending attempts:

  • A fixed delay is applied between sending messages to reduce detection risk.

Recommendations:

  • Tune delays based on target rate and provider feedback.
  • Consider exponential backoff on errors and dynamic pacing based on response codes.

Proxy configuration options#

The current configuration does not set explicit proxy options for puppeteer. To route traffic through a proxy:

  • Add a proxy server argument to puppeteer args in the main process.
  • Alternatively, configure system-level proxy or environment variables consumed by the underlying Chromium.

Note: This is a configuration extension and not currently implemented in the codebase.

Performance tuning and resource allocation#

Observations:

  • Headless Chromium reduces CPU and memory usage compared to headed mode.
  • Sandboxed flags improve stability on constrained systems.
  • The app deletes cache/auth directories to prevent accumulation of stale data.

Recommendations:

  • Monitor memory usage and consider periodic restarts for long-running sessions.
  • Disable unnecessary features via puppeteer args to reduce overhead.
  • Use LocalAuth with a dedicated baseDir for isolation and easier cleanup.

Error handling, authentication timeouts, and recovery#

  • QR loading failures: The UI displays an error state and offers a retry action.
  • Authentication failures: The client emits auth_failure; the main process forwards a status message.
  • Disconnections: The client emits disconnected; the main process resets state.
  • Logout: Attempts logout, then forces cleanup of cache/auth directories.

Recovery steps:

  • Retry connection after clearing cache/auth directories.
  • Ensure network connectivity and device availability.
  • Re-scan QR if the session becomes invalid.

Dependency analysis#

External libraries involved in WhatsApp integration:

  • whatsapp-web.js: Provides the WhatsApp client and authentication strategy.
  • qrcode: Converts QR strings to data URLs for display.
  • puppeteer-core: Underlying browser engine for the WhatsApp client.

Performance considerations#

  • Headless mode reduces resource consumption.
  • Sandboxed flags improve stability on restricted environments.
  • Periodic cleanup of cache and auth directories prevents bloat.
  • Implementing configurable delays and backoff improves resilience and reduces rate-limit penalties.

[No sources needed since this section provides general guidance]

Troubleshooting guide#

Common issues and resolutions:

  • QR code not loading: Check network connectivity, restart the app, and retry scanning.
  • Authentication failure: Clear cache/auth directories and re-scan QR.
  • Disconnection: The app resets state; reconnect using the UI controls.
  • Logout errors: The app performs forced cleanup; reinitialize the client.

Operational tips:

  • Use the activity log to track status and errors.
  • Ensure the Electron environment is properly initialized before invoking APIs.

Conclusion#

The application integrates WhatsApp Web using a hardened headless Chromium configuration with LocalAuth for session persistence. It provides a reliable UI for QR-based authentication, real-time status updates, and basic rate limiting. For production deployments, consider adding proxy support, configurable puppeteer options, and improved error recovery strategies.